package com.example.sxproject.service.impl;

import com.example.sxproject.mapper.CardMapper;
import com.example.sxproject.mapper.UserMapper;
import com.example.sxproject.pojo.Card;
import com.example.sxproject.pojo.User;
import com.example.sxproject.service.UserService;
import com.example.sxproject.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByPhone(String phone) {
        User user = userMapper.findByPhone(phone);
        return user;
    }

    @Override
    public void register(String phone, String password, Integer userType) {
        //加密
        //String md5String =  Md5Util.getMD5String(password);
//        User newUser = new User();
//        newUser.setPhone(phone);
//        newUser.setPassword(password);

        //添加
        userMapper.add(phone, password, userType);
    }

    @Override
    public User findByHouseNumber(String houseNumber) {
        User h =userMapper.findByHouseNumber(houseNumber);
        return h;
    }

    @Override
    public List<User> selectUser(User user){
        List<User> users=userMapper.SelectUser(user);
        return users;
    }

    @Override
    public  List<User> selectAll(){
        List<User> users=userMapper.selectAll();
        return users;
    }
//修改个人信息
    @Override
    public void updateInformation(User user) {
        userMapper.updateInformation(user);
    }

    //更新：更改登录密码
    @Override
    public void changePassword(String phone, String password) {
        userMapper.changePassword(phone, password);
    }

    //更新：实现用户假删除
    @Override
    public void deleteUser( Integer id) {
        userMapper.deleteUser(id);
    }

    @Override
    public void addUserMessage(User user){userMapper.addUserMessage(user);}

   @Override
    public void userMessageUpdate(User user) {
        userMapper.userMessageUpdate(user);
    }

   @Override
    public void userMessageDel(Integer id){userMapper.userMessageDel(id);}

}
